package ru.ssau.customerManagement.controller.remoting.notifications;

import ru.ssau.customerManagement.controller.NotificationListener;
import ru.ssau.customerManagement.model.entities.Customer;
import ru.ssau.customerManagement.model.entities.CustomerLocation;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by illabefat on 25.11.14.
 */
public class ClientSideNotificationControllerImpl implements ClientSideNotificationController{
    private List<NotificationListener> listeners;

    public ClientSideNotificationControllerImpl() {
        listeners = new ArrayList<NotificationListener>();
    }

    @Override
    public void customerChanged(Customer customer) {
        for (NotificationListener listener : listeners)
        {
            listener.customerChanged(customer);
        }
    }

    @Override
    public void customerAdded(Customer customer) {
        for (NotificationListener listener : listeners)
        {
            listener.customerAdded(customer);
        }
    }

    @Override
    public void customerRemoved(Long id) {
        for (NotificationListener listener : listeners)
        {
            listener.customerRemoved(id);
        }
    }

    @Override
    public void customerLocationChanged(CustomerLocation location) {
        for (NotificationListener listener : listeners)
        {
            listener.customerLocationChanged(location);
        }
    }

    @Override
    public void customerLocationAdded(CustomerLocation location) {
        for (NotificationListener listener : listeners)
        {
            listener.customerLocationAdded(location);
        }
    }

    @Override
    public void customerLocationRemoved(Long id) {
        for (NotificationListener listener : listeners)
        {
            listener.customerLocationRemoved(id);
        }
    }

    @Override
    public void registerListener(NotificationListener listener)
    {
        listeners.add(listener);
    }
}
